/*
    $Header: /Windows/Shell/ShellExt.root/ShellExt/src/CStream.h 1     08-01-05 0:08 Ken $
    $Log: /Windows/Shell/ShellExt.root/ShellExt/src/CStream.h $
 * 
 * 1     08-01-05 0:08 Ken

*/

#pragma once


class CStream
{
public:
    CStream(void):m_hFile(INVALID_HANDLE_VALUE){};
    ~CStream(void);

public:
    static HANDLE CreateStrm(const TCHAR *pszFile, const TCHAR *pszStrm, DWORD dwDesiredAccess=GENERIC_READ|GENERIC_WRITE, DWORD dwCreationDispostion=0);
    static BOOL DelStrm(TCHAR* pszFile, TCHAR* pszStrm);
    static BOOL HasStrm(TCHAR* pszFile);
private:
    static HANDLE CreateStrm(const TCHAR *pszFullName, DWORD dwDesiredAccess=GENERIC_READ|GENERIC_WRITE, DWORD dwCreationDispostion=0);
    static BOOL DelStrm(TCHAR* pszFullName){return DeleteFile(pszFullName);};

////////////////////
// enum stream
// Note: no synchronize protect now
public:
    BOOL BegEnum(TCHAR* pszFile);
    BOOL Next(DWORD* pdwNameSize, DWORD* pdwDataSize){return Next(pdwNameSize, pdwDataSize, FALSE);};
    DWORD GetName(TCHAR* pszName, DWORD dwSize);
    DWORD Skip(DWORD dwNum);
    BOOL Reset();
    VOID EndEnum(){CloseHandle(m_hFile);m_hFile=INVALID_HANDLE_VALUE;};

private:
    BOOL Next(DWORD* pdwNameSize, DWORD* pdwDataSize, BOOL fSkip);
private:
    CString    m_cstrName;
    HANDLE m_hFile;
    LPVOID m_lpContext;
    WIN32_STREAM_ID m_sid;
    WCHAR m_wszStrmName[MAX_PATH];
    DWORD m_dwNameLen;

    const static DWORD WIN32_STREAM_ID_SIZE=(DWORD)(&(((WIN32_STREAM_ID*)(0))->cStreamName));
};
